package com.qilu.pe.ui.fragment;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.qilu.pe.R;
import com.qilu.pe.dao.bean.SetDetail;
import com.ruitu.arad.base.BaseFragment;
import com.ruitu.arad.base.base_list.ListBaseAdapter;
import com.ruitu.arad.base.base_list.SuperViewHolder;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

// 套餐详情2检测项目
public class SetDetail2Fragment extends BaseFragment {
    private RecyclerView rcv_test_list;

    private TestItemListAdapter adapter;

    private SetDetail detail;

    public SetDetail2Fragment() {

    }

    public static SetDetail2Fragment newInstance(String param1, SetDetail detail) {
        SetDetail2Fragment fragment = new SetDetail2Fragment();
        Bundle args = new Bundle();
        args.putSerializable("detail", detail);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        detail = (SetDetail) getArguments().getSerializable("detail");
        adapter = new TestItemListAdapter(getActivity());
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.fragment_set_detail2, container, false);
        rcv_test_list = v.findViewById(R.id.rcv_test_list);

        LinearLayoutManager manager = new LinearLayoutManager(getActivity());
        rcv_test_list.setLayoutManager(manager);
        rcv_test_list.setAdapter(adapter);
        adapter.setDataList(detail.getProject_list());

        return v;
    }

    private class TestItemListAdapter extends ListBaseAdapter<SetDetail.Project> {

        public TestItemListAdapter(Context context) {
            super(context);
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_set_project_list;
        }

        @Override
        public void onBindItemHolder(SuperViewHolder holder, int position) {
            TextView tv_pro_name = holder.getView(R.id.tv_pro_name);
            TextView tv_pro_desc = holder.getView(R.id.tv_pro_desc);

            SetDetail.Project project = mDataList.get(position);
            tv_pro_name.setText(project.getName());
            tv_pro_desc.setText(project.getSignificance());
        }
    }
}